home *** CD-ROM | disk | FTP | other *** search
/ GFX Sensations 1 / Graphic Sensations - Volume 1.iso / com_net / tcp / amitcp / netinclude / sys / socket.h < prev    next >
C/C++ Source or Header  |  2000-01-01  |  10KB  |  299 lines

  1. /*
  2.  * $Id: socket.h,v 3.1 1994/01/24 16:06:03 too Exp $
  3.  *
  4.  * Copyright (c) 1993 AmiTCP/IP Group, <amitcp-group@hut.fi>
  5.  *                    Helsinki University of Technology, Finland.
  6.  *                    All rights reserved.
  7.  *
  8.  * HISTORY
  9.  * $Log: socket.h,v $
  10.  * Revision 3.1  1994/01/24  16:06:03  too
  11.  * Added definition of `struct iovec'
  12.  *
  13.  * Revision 1.11  1993/07/07  14:55:52  too
  14.  * Removed inclusion of CLIB_SOCKET_PROTOS_H
  15.  *
  16.  * Revision 1.10  1993/06/04  11:16:15  jraja
  17.  * Fixes for first public release.
  18.  *
  19.  * Revision 1.9  1993/06/01  08:12:25  jraja
  20.  * Added definition UNIQUE_ID to be used with Release(CopyOf)Socket().
  21.  *
  22.  * Revision 1.6  1993/04/26  11:22:59  jraja
  23.  * Updated to include socket protos/pragmas/inlines (if not in KERNEL).
  24.  *
  25.  * Revision 1.5  93/04/13  21:59:15  21:59:15  jraja (Jarno Tapio Rajahalme)
  26.  * Added inline/prototype for Select() function (#ifndef KERNEL).
  27.  * 
  28.  * Revision 1.4  93/03/22  01:25:21  01:25:21  ppessi (Pekka Pessi)
  29.  * An API version of socket.h
  30.  * 
  31.  * Revision 1.1  92/11/20  15:42:36  15:42:36  jraja (Jarno Tapio Rajahalme)
  32.  * Initial revision
  33.  *
  34.  */
  35.  
  36. /*
  37.  * Copyright (c) 1982,1985,1986,1988 Regents of the University of California.
  38.  * All rights reserved.
  39.  *
  40.  * Redistribution and use in source and binary forms, with or without
  41.  * modification, are permitted provided that the following conditions
  42.  * are met:
  43.  * 1. Redistributions of source code must retain the above copyright
  44.  *    notice, this list of conditions and the following disclaimer.
  45.  * 2. Redistributions in binary form must reproduce the above copyright
  46.  *    notice, this list of conditions and the following disclaimer in the
  47.  *    documentation and/or other materials provided with the distribution.
  48.  * 3. All advertising materials mentioning features or use of this software
  49.  *    must display the following acknowledgement:
  50.  *    This product includes software developed by the University of
  51.  *    California, Berkeley and its contributors.
  52.  * 4. Neither the name of the University nor the names of its contributors
  53.  *    may be used to endorse or promote products derived from this software
  54.  *    without specific prior written permission.
  55.  *
  56.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  57.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  58.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  59.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  60.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  61.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  62.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  63.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  64.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  65.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  66.  * SUCH DAMAGE.
  67.  *
  68.  *    @(#)socket.h    7.13 (Berkeley) 4/20/91
  69.  */
  70.  
  71. #ifndef SYS_SOCKET_H
  72. #define SYS_SOCKET_H
  73.  
  74. #ifndef SYS_TYPES_H
  75. #include <sys/types.h>
  76. #endif
  77.  
  78. /*
  79.  * Definitions related to sockets: types, address families, options.
  80.  */
  81.  
  82. /*
  83.  * Definition for Release(CopyOf)Socket unique id
  84.  */
  85. #define UNIQUE_ID    (-1)
  86.  
  87. /*
  88.  * Types
  89.  */
  90. #define    SOCK_STREAM    1        /* stream socket */
  91. #define    SOCK_DGRAM    2        /* datagram socket */
  92. #define    SOCK_RAW    3        /* raw-protocol interface */
  93. #define    SOCK_RDM    4        /* reliably-delivered message */
  94. #define    SOCK_SEQPACKET    5        /* sequenced packet stream */
  95.  
  96. /*
  97.  * Option flags per-socket.
  98.  */
  99. #define    SO_DEBUG    0x0001        /* turn on debugging info recording */
  100. #define    SO_ACCEPTCONN    0x0002        /* socket has had listen() */
  101. #define    SO_REUSEADDR    0x0004        /* allow local address reuse */
  102. #define    SO_KEEPALIVE    0x0008        /* keep connections alive */
  103. #define    SO_DONTROUTE    0x0010        /* just use interface addresses */
  104. #define    SO_BROADCAST    0x0020        /* permit sending of broadcast msgs */
  105. #define    SO_USELOOPBACK    0x0040        /* bypass hardware when possible */
  106. #define    SO_LINGER    0x0080        /* linger on close if data present */
  107. #define    SO_OOBINLINE    0x0100        /* leave received OOB data in line */
  108.  
  109. /*
  110.  * Additional options, not kept in so_options.
  111.  */
  112. #define SO_SNDBUF    0x1001        /* send buffer size */
  113. #define SO_RCVBUF    0x1002        /* receive buffer size */
  114. #define SO_SNDLOWAT    0x1003        /* send low-water mark */
  115. #define SO_RCVLOWAT    0x1004        /* receive low-water mark */
  116. #define SO_SNDTIMEO    0x1005        /* send timeout */
  117. #define SO_RCVTIMEO    0x1006        /* receive timeout */
  118. #define    SO_ERROR    0x1007        /* get error status and clear */
  119. #define    SO_TYPE        0x1008        /* get socket type */
  120.  
  121. /*
  122.  * Structure used for manipulating linger option.
  123.  */
  124. struct    linger {
  125.     int    l_onoff;        /* option on/off */
  126.     int    l_linger;        /* linger time */
  127. };
  128.  
  129. /*
  130.  * Level number for (get/set)sockopt() to apply to socket itself.
  131.  */
  132. #define    SOL_SOCKET    0xffff        /* options for socket level */
  133.  
  134. /*
  135.  * Address families.
  136.  */
  137. #define    AF_UNSPEC    0        /* unspecified */
  138. #define    AF_UNIX        1        /* local to host (pipes, portals) */
  139. #define    AF_INET        2        /* internetwork: UDP, TCP, etc. */
  140. #define    AF_IMPLINK    3        /* arpanet imp addresses */
  141. #define    AF_PUP        4        /* pup protocols: e.g. BSP */
  142. #define    AF_CHAOS    5        /* mit CHAOS protocols */
  143. #define    AF_NS        6        /* XEROX NS protocols */
  144. #define    AF_ISO        7        /* ISO protocols */
  145. #define    AF_OSI        AF_ISO
  146. #define    AF_ECMA        8        /* european computer manufacturers */
  147. #define    AF_DATAKIT    9        /* datakit protocols */
  148. #define    AF_CCITT    10        /* CCITT protocols, X.25 etc */
  149. #define    AF_SNA        11        /* IBM SNA */
  150. #define AF_DECnet    12        /* DECnet */
  151. #define AF_DLI        13        /* DEC Direct data link interface */
  152. #define AF_LAT        14        /* LAT */
  153. #define    AF_HYLINK    15        /* NSC Hyperchannel */
  154. #define    AF_APPLETALK    16        /* Apple Talk */
  155. #define    AF_ROUTE    17        /* Internal Routing Protocol */
  156. #define    AF_LINK        18        /* Link layer interface */
  157. #define    pseudo_AF_XTP    19        /* eXpress Transfer Protocol (no AF) */
  158.  
  159. #define    AF_MAX        20
  160.  
  161. /*
  162.  * Structure used by kernel to store most
  163.  * addresses.
  164.  */
  165. struct sockaddr {
  166.     u_char    sa_len;            /* total length */
  167.     u_char    sa_family;        /* address family */
  168.     char    sa_data[14];        /* actually longer; address value */
  169. };
  170.  
  171. /*
  172.  * Structure used by kernel to pass protocol
  173.  * information in raw sockets.
  174.  */
  175. struct sockproto {
  176.     u_short    sp_family;        /* address family */
  177.     u_short    sp_protocol;        /* protocol */
  178. };
  179.  
  180. /*
  181.  * Protocol families, same as address families for now.
  182.  */
  183. #define    PF_UNSPEC    AF_UNSPEC
  184. #define    PF_UNIX        AF_UNIX
  185. #define    PF_INET        AF_INET
  186. #define    PF_IMPLINK    AF_IMPLINK
  187. #define    PF_PUP        AF_PUP
  188. #define    PF_CHAOS    AF_CHAOS
  189. #define    PF_NS        AF_NS
  190. #define    PF_ISO        AF_ISO
  191. #define    PF_OSI        AF_ISO
  192. #define    PF_ECMA        AF_ECMA
  193. #define    PF_DATAKIT    AF_DATAKIT
  194. #define    PF_CCITT    AF_CCITT
  195. #define    PF_SNA        AF_SNA
  196. #define PF_DECnet    AF_DECnet
  197. #define PF_DLI        AF_DLI
  198. #define PF_LAT        AF_LAT
  199. #define    PF_HYLINK    AF_HYLINK
  200. #define    PF_APPLETALK    AF_APPLETALK
  201. #define    PF_ROUTE    AF_ROUTE
  202. #define    PF_LINK        AF_LINK
  203. #define    PF_XTP        pseudo_AF_XTP    /* really just proto family, no AF */
  204.  
  205. #define    PF_MAX        AF_MAX
  206.  
  207. /*
  208.  * Maximum queue length specifiable by listen.
  209.  */
  210. #define    SOMAXCONN    5
  211.  
  212. /*
  213.  * Message header for recvmsg and sendmsg calls.
  214.  * Used value-result for recvmsg, value only for sendmsg.
  215.  */
  216. struct iovec {
  217.     caddr_t    iov_base;
  218.     int    iov_len;
  219. };
  220.  
  221. struct msghdr {
  222.     caddr_t    msg_name;        /* optional address */
  223.     u_int    msg_namelen;        /* size of address */
  224.     struct    iovec *msg_iov;        /* scatter/gather array */
  225.     u_int    msg_iovlen;        /* # elements in msg_iov */
  226.     caddr_t    msg_control;        /* ancillary data, see below */
  227.     u_int    msg_controllen;        /* ancillary data buffer len */
  228.     int    msg_flags;        /* flags on received message */
  229. };
  230.  
  231. #define    MSG_OOB        0x1        /* process out-of-band data */
  232. #define    MSG_PEEK    0x2        /* peek at incoming message */
  233. #define    MSG_DONTROUTE    0x4        /* send without using routing tables */
  234. #define    MSG_EOR        0x8        /* data completes record */
  235. #define    MSG_TRUNC    0x10        /* data discarded before delivery */
  236. #define    MSG_CTRUNC    0x20        /* control data lost before delivery */
  237. #define    MSG_WAITALL    0x40        /* wait for full request or error */
  238.  
  239. /*
  240.  * Header for ancillary data objects in msg_control buffer.
  241.  * Used for additional information with/about a datagram
  242.  * not expressible by flags.  The format is a sequence
  243.  * of message elements headed by cmsghdr structures.
  244.  */
  245. struct cmsghdr {
  246.     u_int    cmsg_len;        /* data byte count, including hdr */
  247.     int    cmsg_level;        /* originating protocol */
  248.     int    cmsg_type;        /* protocol-specific type */
  249. /* followed by    u_char  cmsg_data[]; */
  250. };
  251.  
  252. /* given pointer to struct adatahdr, return pointer to data */
  253. #define    CMSG_DATA(cmsg)        ((u_char *)((cmsg) + 1))
  254.  
  255. /* given pointer to struct adatahdr, return pointer to next adatahdr */
  256. #define    CMSG_NXTHDR(mhdr, cmsg)    \
  257.     (((caddr_t)(cmsg) + (cmsg)->cmsg_len + sizeof(struct cmsghdr) > \
  258.         (mhdr)->msg_control + (mhdr)->msg_controllen) ? \
  259.         (struct cmsghdr *)NULL : \
  260.         (struct cmsghdr *)((caddr_t)(cmsg) + ALIGN((cmsg)->cmsg_len)))
  261.  
  262. #define    CMSG_FIRSTHDR(mhdr)    ((struct cmsghdr *)(mhdr)->msg_control)
  263.  
  264. /* "Socket"-level control message types: */
  265. #define    SCM_RIGHTS    0x01        /* access rights (array of int) */
  266.  
  267. /*
  268.  * 4.3 compat sockaddr, move to compat file later
  269.  */
  270. struct osockaddr {
  271.     u_short    sa_family;        /* address family */
  272.     char    sa_data[14];        /* up to 14 bytes of direct address */
  273. };
  274.  
  275. /*
  276.  * 4.3-compat message header (move to compat file later).
  277.  */
  278. struct omsghdr {
  279.     caddr_t    msg_name;        /* optional address */
  280.     int    msg_namelen;        /* size of address */
  281.     struct    iovec *msg_iov;        /* scatter/gather array */
  282.     int    msg_iovlen;        /* # elements in msg_iov */
  283.     caddr_t    msg_accrights;        /* access rights sent/received */
  284.     int    msg_accrightslen;
  285. };
  286.  
  287. #ifndef KERNEL
  288.  
  289. /*
  290.  * Include socket protos/inlines/pragmas
  291.  */
  292. #ifndef BSDSOCKET_H
  293. #include <bsdsocket.h>
  294. #endif
  295.  
  296. #endif /* !KERNEL */
  297.  
  298. #endif /* !SYS_SOCKET_H */
  299.